package com.cheng.example.atguigu.design_pattern.factory.simple;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 订单披萨
 */
public class OrderPizza2 {
//    SimpleFactory simpleFactory;
    Pizza pizza = null;

    // 构造方法

    public OrderPizza2() {
        setFactory();
    }

    public void setFactory() {
        String ordertype = "";
//        this.simpleFactory = simpleFactory;
        do {
            ordertype = getType();
            pizza = SimpleFactory.createPizza2(ordertype);

            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购失败");
                break;
            }
        } while (true);
    }

    public String getType() {
        try {
            BufferedReader strin =
                    new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
